package com.taptech.doufu.ui.fragment.NovelChildFragments;

import android.os.Bundle;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.taobao.weex.utils.WXResourceUtils;
import com.taptech.doufu.R;
import com.taptech.doufu.ui.activity.NovelSectionDetailsActivity;
import com.taptech.doufu.ui.activity.weex.SimpleWeexActivity;
import com.taptech.doufu.bean.HomeTopBean;
import com.taptech.doufu.ui.fragment.weex.TFWXFragment;

import java.util.HashMap;

/**
 * Created by op0509 on 2016/6/27.
 */
public class NovelToSweepFragment extends TFWXFragment implements View.OnClickListener {
    private NovelSectionDetailsActivity activity;
    private TextView jumpToSweepBtn ;
    private String novelId;
    private LinearLayout lineMorePop;
    private HomeTopBean topicBean;

    public static final String ARG_NOVEL_ID = "arg_novel_id";
    @Override
    public void onCreate(Bundle savedInstanceState) {
        HashMap<String, String> data = new HashMap<>();
        Bundle bundle = getArguments();
        String novelId = bundle.getString(ARG_NOVEL_ID);
        data.put("id", novelId);
        data.put("object_type", String.valueOf(18));
        HashMap param = new HashMap();
        param.put("url","TFNovel/TFNovelFooter.js?id="+novelId);
        param.put("data", data);
        super.param = param;
        super.onCreate(savedInstanceState);
    }

    public static NovelToSweepFragment newInstance(String novelId){
        NovelToSweepFragment fragment = new NovelToSweepFragment();
        Bundle bundle = new Bundle();
        bundle.putString(ARG_NOVEL_ID, novelId);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        activity = (NovelSectionDetailsActivity) getActivity();
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.novel_to_sweep_activity_layout, null);
        }
        lay = (LinearLayout) rootView.findViewById(R.id.lay);
        rootView.setBackgroundColor(WXResourceUtils.getColor("bg|bg"));
        initView(rootView);
        initData();
        return rootView;
    }


    private boolean hasInitData = false;
    public void initData() {
        if (hasInitData) {
            return;
        }
        if (activity!=null){
            novelId = activity.novelId;
            topicBean = activity.topicBean;
        }
        if(topicBean != null){
            hasInitData = true;
        }
    }

    private void initView(View view) {
        jumpToSweepBtn = (TextView) view.findViewById(R.id.jump_to_sweep_btn);
        jumpToSweepBtn.setOnClickListener(this);
        lineMorePop=(LinearLayout) view.findViewById(R.id.layout_reader_toolbar_top_more);
        lineMorePop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.jump_to_sweep_btn:
                SimpleWeexActivity.startActivity(activity,"vue/articalComment/TFArticalComment.js?novelId="+novelId);
                break;
            case R.id.layout_reader_toolbar_top_more:
                activity.showToTo();
                break;
            default:
                break;
        }
    }

    public void topBack(View view){
        activity.onBackPressed();
    }
}
